﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using IronCow.Search;

namespace IronCow.UnitTests
{
    public static class AssertExtensions
    {
        public static void AreNodeEqual(Node expected, Node actual)
        {
            if (expected != null)
                Assert.IsNotNull(actual);
            Assert.AreSame(expected.GetType(), actual.GetType());
            if (expected is BooleanNode)
            {
                Assert.AreEqual(((BooleanNode)expected).Type, ((BooleanNode)actual).Type);
            }
            else if (expected is TermNode)
            {
                Assert.AreEqual(((TermNode)expected).Term, ((TermNode)actual).Term);
            }
            else if (expected is OperatorNode)
            {
                Assert.AreEqual(((OperatorNode)expected).Name, ((OperatorNode)actual).Name);
            }

            Assert.AreEqual(expected.Count(), actual.Count());
            IEnumerator<Node> expectedEnum = expected.GetEnumerator();
            IEnumerator<Node> actualEnum = actual.GetEnumerator();
            while(actualEnum.MoveNext() && expectedEnum.MoveNext())
            {
                AreNodeEqual(expectedEnum.Current, actualEnum.Current);
            }
        }
    }
}
